package com.le.buddha.controller;

import com.le.buddha.common.BusinessRuntimeException;
import com.le.buddha.common.Response;
import com.le.buddha.common.ResultCode;
import com.le.buddha.conf.UserUtil;
import com.le.buddha.mobile.ChatHistory;
import com.le.buddha.mobile.vo.ChatHistoryVO;
import com.le.buddha.service.IChatHistoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/app/chatHistory")
public class AppChatHistoryController {
    @Resource
    private IChatHistoryService chatHistoryService;

    /**
     * 获取用户聊天记录列表
     *
     * @return
     */

    @GetMapping("/historyList")
    public Response historyList(HttpServletRequest request) {
        Long userId = UserUtil.getUserId(request);

        List<ChatHistoryVO> historyVOList = chatHistoryService.queryUserHistoryList(userId);


        return Response.success(historyVOList);
    }

    /**
     * 删除用户历史记录
     * @param request
     * @return
     */
    @GetMapping("/clearHistory")
    public Response clearHistory(HttpServletRequest request) {
        Long userId = UserUtil.getUserId(request);
        chatHistoryService.lambdaUpdate().eq(ChatHistory::getUserId, userId).remove();
        return Response.success();
    }
}
